<?php

/**
 * This is the model class for table "post_category".
 *
 * The followings are the available columns in table 'post_category':
 * @property string $id
 * @property string $parent_id
 * @property string $title
 * @property integer $sorter
 * @property string $desc
 * @property string $header
 * @property string $footer
 * @property string $thumbnail
 * @property integer $show_home
 * @property integer $show_menu
 * @property string $seo_link
 * @property string $seo_title
 * @property string $seo_keyword
 * @property string $seo_description
 * @property integer $status
 * @property string $date_created
 * @property string $date_edited
 *
 * The followings are the available model relations:
 * @property Post[] $posts
 */
class PostCategory extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return PostCategory the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'post_category';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('title, date_created', 'required'),
			array('sorter, show_home, show_menu, status', 'numerical', 'integerOnly'=>true),
			array('parent_id', 'length', 'max'=>10),
			array('title, seo_link, seo_title', 'length', 'max'=>255),
			array('desc, header, footer, thumbnail, seo_keyword, seo_description, date_edited', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, parent_id, title, sorter, desc, header, footer, thumbnail, show_home, show_menu, seo_link, seo_title, seo_keyword, seo_description, status, date_created, date_edited', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'posts' => array(self::HAS_MANY, 'Post', 'post_category_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'parent_id' => 'Parent',
			'title' => 'Title',
			'sorter' => 'Sorter',
			'desc' => 'Desc',
			'header' => 'Header',
			'footer' => 'Footer',
			'thumbnail' => 'Thumbnail',
			'show_home' => 'Show Home',
			'show_menu' => 'Show Menu',
			'seo_link' => 'Seo Link',
			'seo_title' => 'Seo Title',
			'seo_keyword' => 'Seo Keyword',
			'seo_description' => 'Seo Description',
			'status' => 'Status',
			'date_created' => 'Date Created',
			'date_edited' => 'Date Edited',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('parent_id',$this->parent_id,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('sorter',$this->sorter);
		$criteria->compare('desc',$this->desc,true);
		$criteria->compare('header',$this->header,true);
		$criteria->compare('footer',$this->footer,true);
		$criteria->compare('thumbnail',$this->thumbnail,true);
		$criteria->compare('show_home',$this->show_home);
		$criteria->compare('show_menu',$this->show_menu);
		$criteria->compare('seo_link',$this->seo_link,true);
		$criteria->compare('seo_title',$this->seo_title,true);
		$criteria->compare('seo_keyword',$this->seo_keyword,true);
		$criteria->compare('seo_description',$this->seo_description,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('date_created',$this->date_created,true);
		$criteria->compare('date_edited',$this->date_edited,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}